<%--
  Created by IntelliJ IDEA.
  User: ACER
  Date: 2024/12/3
  Time: 08:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>异步提交商品</title>
</head>
<body>
<script src="static/js.jquery.min"></script>
<form id="products">
  <table border="1">
    <tr>
      <td>
        <input name="proId" value="1" id="proId" type="text">
      </td>
      <td>
        <input name="proName" value="三文鱼" id="proName" type="text">
      </td>
      <td>
        <input  type="button" value="提交单个商品" onclick="submitProduct()">
      </td>
    </tr>
    <td>
      <input name="proId" value="2" id="proId2" type="text">
    </td>
    <td>
      <input name="proName" value="红牛" id="proName2" type="text">
    </td>
    <td>
      <input  type="button" value="提交多个商品" onclick="submitProducts()">
    </td>
    </tr>
  </table>
</form>
<script type="text/javascript">
  function  sumbitProduct(){
    var proId=$("proId").val();
    var proName=$("proName").val();
    $.ajax({
      url:"${pageContext.request.contextPath}/getProduct",
      type:"post",
      data:JSON.stringify({proId: proId,proName: proName}),
      contentType: "application/json;charset=UTF-8",
      dataTypea:"json",
      success:function (response){alert(response);}
    });
  }
  function  sumbitProducts(){
    var pro1={proId:$("proId").val(),proName:$("#proName").val()};
    var pro2={proId:$("proId2").val(),proName:$("#proName2").val()};
    $.ajax({
      url:"${pageContext.request.contextPath}/getProduct",
      type:"post",
      data:JSON.stringify({proId: proId,proName: proName}),
      contentType: "application/json;charset=UTF-8",
      dataTypea:"json",
      success:function (response){alert(response);}
    });
  }
</script>
</body>
</html>
